/*
 * Searcher.java
 *
 * Created on 28 luglio 2005, 10.12
 *
 * @version 1.1
 * @author Federico Paparoni
 *
 */

package com.javastaff.btfree;
import javax.bluetooth.*;
import java.util.*;

public class Searcher implements DiscoveryListener{
    
    private int count;
    private Vector utentiTrovati;
    private int completati=0;
    private int finito=0;
    private Vector devicesFound;
    private String SERVICE_NAME; 
    
    private SearcherServer searcherServer;
    private ServiceRecord serviceRecord;
    
    public Searcher(SearcherServer searcherServer,String nome) {
        this.searcherServer = searcherServer;
        this.SERVICE_NAME=nome;
        devicesFound=new Vector();
   }
    
    public void servicesDiscovered(int transID, ServiceRecord[] servRecord) {
        for(int i = 0; i < servRecord.length; i++) {
            DataElement serviceNameElement = servRecord[i].getAttributeValue(0x0100);
            String serviceName = (String)serviceNameElement.getValue();
            if(serviceName.equals(SERVICE_NAME)){
                serviceRecord = servRecord[i];
                break;
            }
        }
    }
    public void serviceSearchCompleted(int transID, int respCode) {
        searcherServer.servicesFound(serviceRecord);
        serviceRecord = null;
    }
    
    public void inquiryCompleted(int discType){
        searcherServer.devicesFound(devicesFound);
    }
    
    public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod){
        devicesFound.addElement(btDevice);
    }
}
